<?php

namespace Home\Controller;
use Think\Controller;

/**
*app活动类控制器
* @param type
* @autho cheng
*/
class ActivityController extends BaseController {

    /**
     * Function StationActivity
     * Author: quyang
     * Date: 2017-2-4 13:56
     * Info: app活动
     */
    public function StationActivity(){

        $param = I('param.');

        if ($param['type'] == ''){
            $this->param_error();
        }

        $page = $param['page'] ? $param['page'] : 1;

        $where['type'] = $param['type'];

        //获取版本信息
        $source = I('get.');

        //默认值
        $dataNum = '0';

        $data['list'] = [];

        //判断不为苹果时查询对应数据( 苹果和安卓活动不一样 )
        if ( $source['bmxSource'] != 'ios' )
        {
            $dataNum = D('Activity')->where($where)->count('f_id');

            $data['list'] = D('Activity')
                ->field("*,FROM_UNIXTIME( `f_create_time`, '%Y-%m-%d') as fCreateTime, CONCAT( '". CURRENT_DOMAIN ."/?reqUrl=ActivityView.activityList&fid=', `f_id` ) AS `f_url`")
                ->where($where)
                ->page($page,20)
                ->order('f_create_time DESC')
                ->select();
        }
        //苹果活动
        else
        {

        }

        $data['page'] = "$page";

        $data['pageNum'] = '20';

        $data['pagetotle'] = $dataNum;

        $this->output(true,$data);

    }

    /**
     * Function appNotice
     *
     * Author: quyang
     * Date: 2017-2-7 13:19
     * Info: app通知消息
     */
    public function appNotice(){

        $param = I('param.');

        if ( empty( $param['userId'] ) ){
            $this->param_error();
        }

        $page = $param['page'] ? $param['page'] : 1;

        $data['page'] = $page;
        $data['pageNum'] = '20';

        $where['f_receive_id'] = $param['userId'];

        $data['pagetotle'] = D('AppNotice')->where( $where )->count('f_id');
        $data['list'] = D('AppNotice')->where( $where )->field("*,FROM_UNIXTIME( `f_create_time`, '%Y-%m-%d') as fCreateTime")->page( $page , $data['pageNum'] )->order('f_create_time DESC')->select();

        $this->output(true,$data);

    }

    /**
     * Function appNoticeRegister
     *
     * Author: quyang
     * Date: 2017-2-7 13:19
     * Info: app通知消息详情
     */
    public function appNoticeRegister(){

        $param = I('param.');

        empty($param['fId']) && $this->param_error();

        $where['f_id'] = $param['fId'];

        $data = D('AppNotice')->field("*,FROM_UNIXTIME( `f_create_time`, '%Y-%m-%d') as fCreateTime")->where($where)->find();

        $this->output(true,$data);

    }

}
